package com.jdk8.lambda;

import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class BiFunctionTest {

	 public static void main(String[] args) {
	        BiFunctionTest biFunction= new BiFunctionTest();
//	        System.out.println(biFunction.compute(4,5,(a,b) -> a * b,a -> a * 2));
	        List<Integer> intList=Arrays.asList(1,2,3,4,5,6,7,8,9,10);
//	        biFunction.conditionFilterAnd(intList, i ->i>5,i -> i%2==0).forEach(System.out::println);
//	        biFunction.conditionFilterNegate(intList, i -> i%2==0).forEach(System.out::println);   
	        System.out.println(Predicate.isEqual("ok").test("OK"));
	 }

	    public int compute(int a, int b, BiFunction<Integer,Integer,Integer> biFunction,
	                       Function<Integer,Integer> function){
	        return biFunction.andThen(function).apply(a,b);
	    }
	    public List<Integer> conditionFilterAnd(List<Integer> list, Predicate<Integer> predicate,Predicate<Integer> predicate2){
	        return list.stream().filter(predicate.and(predicate2)).collect(Collectors.toList());
	    }
	    public List<Integer> conditionFilterOr(List<Integer> list, Predicate<Integer> predicate,Predicate<Integer> predicate2){
	        return list.stream().filter(predicate.or(predicate2)).collect(Collectors.toList());
	    }
	    public List<Integer> conditionFilterNegate(List<Integer> list, Predicate<Integer> predicate){
	        return list.stream().filter(predicate.negate()).collect(Collectors.toList());
	    }

}
